/**
 * Created by xu on 2016/1/21.
 */

function afterClickTrackPointTab(){
    getTrackPointList();//获取list列表
}

//导出地面标识excel
function exportTrackPointList(){
    var data_=$("#trackPointForm").serializeFormJSON();
    var p=json2UrlParam(data_);
    backgroundExport(p_path+"/pipe/data/trackPoint/trackPointExport2.json?"+p)
    //window.open(p_path+"/pipe/data/trackPoint/trackPointExport.json?"+p);
    //location.href=p_path+"/pipe/data/trackPoint/trackPointExport.json?"+p;
}
function downTrackPoint(){
    location.href=p_path+"/public/down/downTrackPointTemplate.json";
}

//删除
function delTrackPoint(id){
    if (isEmpty(id)){
        alert("删除id不能为空!");
        return;
    }
    if (!confirm("是否确定删除?")){
        return;
    }
    $().invoke(
        p_path+"/pipe/data/trackPoint/delTrackPoint.json",
        {"id":id},
        [function(m,r){
            if (r=='success'){
                $("#trackPoint").refresh();
            }
        },function(m,r){
            alert(r);
        }]
    )

}
//根据条件查询地面标识列表
function queryTrackPointList(){
    var vR=$("#trackPointForm").validationEngine("validate");
    if (!vR){
        return;
    }
    var data_=$("#trackPointForm").serializeFormJSON();
    $("#trackPoint").selectDataAfterSetParm(data_);
}
function getTrackPointList(){
    var col=[
        {title:"管道名称",name:"lineName",width:"10%",align:"center"},
        {title:"管段名称",name:"segmentName",width:"10%",align:"center"},
        {title:"定标点编号",name:"customNumber",width:"5%",align:"center"},
        {title:"定标点类型",name:"type",width:"5%",align:"center"},
        {title:"行政地域名称",name:"adminRegionName",width:"5%",align:"center"},
        {title:"绝对距离(m)",name:"mileage",width:"10%",align:"center",format:function(json){return nvl_(json.mileage,"",0)}},
        {title:"详情",name:"",width:"3%",align:"center",format:dataDeatilTrackPoint}
        /*{title:"删除",name:"",width:"5%",align:"center",format:dataDel}*/
    ];
    $("#trackPoint").initTable({
        url: p_path + "/pipe/data/trackPoint/queryTrackPointList.json",
        columnData: col,
        doubleRowMode:true,
        isrowClick:true,
        maxHeightMode:false,
        //rowClickMethod:pipeTrackPointRowClick,
        isBindDataToTr:true,
        selectDataNow:true
    });
}

function dataDeatilTrackPoint(json){
    var h="<li class=\"w12-4-3-1 no-right\" style='list-style: none;position: relative'>" +
        "<em onclick='opDetail(this,showTrackPointUl)' class=\"xq-icon new\"  style='margin-left:-15px'></em>" +
//        "<em onclick=delTrackPoint('"+json.id+"') class=\"delet2\"></em>"+
        "</li>";
    return h;
}

function pipeTrackPointRowClick(data,obj,orderNum){
    try {
        var eventTarget_ = event.target || event.srcElement;
        if (eventTarget_ != null && eventTarget_ != document&& eventTarget_.tagName=="EM"
            && $(eventTarget_).hasClass("xq-icon")) {
            var t=$("#trackPoint"+orderNum,$("#trackPoint"));
            $("td",t).html(showTrackPointUl(data));
            t.fadeToggle();
            return false;
            /*if ($(eventTarget_).hasClass("delet2")) {
                return;
            }*/
        }
    } catch (e) {
        console.log(e)
    }


}


function showTrackPointUl(json){
    var ulHtml="<div class='info-tr'>";
    ulHtml+=("<div class=\"show-ul \">");
    ulHtml+=("     <ul class=\"show-list\">");
    ulHtml+=("         <li title=>");
    ulHtml+=("             <span class=\"s1\">管道名称:</span>");
    ulHtml+=("             <span class=\"s2\">"+nvl_(json.lineName)+"</span>");
    ulHtml+=("         </li>");
    ulHtml+=("         <li >");
    ulHtml+=("             <span class=\"s1\">管段名称:</span>");
    ulHtml+=("             <span class=\"s2\">"+nvl_(json.segmentName)+"</span>");
    ulHtml+=("         </li>");
    ulHtml+=("         <li >");
    ulHtml+=("             <span class=\"s1\">定标点编号:</span>");
    ulHtml+=("             <span class=\"s2\">"+nvl_(json.customNumber)+"</span>");
    ulHtml+=("         </li>");
    ulHtml+=("         <li >");
    ulHtml+=("             <span class=\"s1\">定标点类型:</span>");
    ulHtml+=("             <span class=\"s2\">"+nvl_(json.type)+"</span>");
    ulHtml+=("         </li>");
    ulHtml+=("         <li >");
    ulHtml+=("             <span class=\"s1\">行政地域名称:</span>");
    ulHtml+=("             <span class=\"s2\">"+nvl_(json.adminRegionName)+"</span>");
    ulHtml+=("         </li>");
    ulHtml+=("         <li >");
    ulHtml+=("             <span class=\"s1\">绝对距离(m):</span>");
    ulHtml+=("             <span class=\"s2\">"+nvl_(json.mileage)+"</span>");
    ulHtml+=("         </li>");


    ulHtml+=("         <li>");
    ulHtml+=("             <span class=\"s1\">记录人:</span>");
    ulHtml+=("             <span class=\"s2\">"+nvl_(json.recorder)+"</span>");
    ulHtml+=("         </li>");
    ulHtml+=("         <li>");
    ulHtml+=("             <span class=\"s1\">记录时间:</span>");
    ulHtml+=("             <span class=\"s2\">"+nvl_(json.recordtime)+"</span>");
    ulHtml+=("         </li>");

    ulHtml+=("         <li>");
    ulHtml+=("             <span class=\"s1\">统一编号:</span>");
    ulHtml+=("             <span class=\"s2\">"+nvl_(json.code)+"</span>");
    ulHtml+=("         </li>");

    ulHtml+=("         <li class=\"last-li\" >");
    ulHtml+=("             <span class=\"s1\">备注:</span>");
    ulHtml+=("             <span class=\"s2\"><textarea placeholder=\"备注描述\">"+nvl_(json.createRemark)+"</textarea></span>");
    ulHtml+=("         </li>");
    ulHtml+=("     </ul>");
    ulHtml+=(" </div></div>");
    return ulHtml;
}